layui.use(["tree"], function () {
    var tree = layui.tree;
    tree({
        elem: "#classtree",
        nodes: JSON.parse($("input[name='data']").val()),
        click: function (node) {
            var $select = $($(this)[0].elem).parents(".custom-select-tree");
            $select.removeClass("layui-form-selected").find(".layui-select-title span").html(node.name).end().find("input:hidden[name='parentCode']").val(node.id);
        }
    });
    $(".custom-select-tree").on("click", ".layui-select-title", function (e) {
        $(".custom-select-tree").not($(this).parents(".custom-select-tree")).removeClass("layui-form-selected");
        $(this).parents(".custom-select-tree").toggleClass("layui-form-selected");
        layui.stope(e);
    }).on("click", "dl i", function (e) {
        layui.stope(e);
    });
    $(document).on("click", function (e) {
        $(".custom-select-tree").removeClass("layui-form-selected");
    });
});
    